package com.tgy.myswagger.controller;

import com.tgy.myswagger.entity.TestParam;
import com.tgy.myswagger.entity.User;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/***
 * @ClassName: TestController
 * @Description:
 * @Auther: 送一一块二向箔
 * @Date: 21:04 2022/1/6
 * @version : V1.0
 */
@Api(value = "测试swagger", tags = {"测试swagger"})
@Controller
public class TestController {

    @ApiOperation("hi接口单独无需参数")
    @ResponseBody
    @GetMapping("/hi")
    public String aa(){
        return "hello";
    }


    @ApiOperation("restful接口")
    @ResponseBody
    @GetMapping("/hi/{p1}")
    public String bb(@ApiParam("restful接口会被返回的参数") @PathVariable String p1){
        return p1;
    }

    @ApiOperation("普通get接口")
    @ResponseBody
    @GetMapping("/hello")
    public String cc(@ApiParam("普通get接口会被返回的参数")@RequestParam("name") String p1){
        return p1;
    }

    @ApiOperation("返回实体类接口")
    @ResponseBody
    @GetMapping("/user")
    public User dd(){
        return new User("aaa","密码");
    }

    @ApiOperation("普通post接口")
    @ResponseBody
    @PostMapping("/post")
    public User ee(@ApiParam("json 入参")@RequestBody Map<String,String> inMap){
        return new User(inMap.get("mz"),inMap.get("mm"));
    }

    @ApiOperation("实体类post接口")
    @ResponseBody
    @PostMapping("/postUser")
    public User ff(@ApiParam("User入参")@RequestBody User user){
        return user;
    }



    @ApiOperation(value = "测试post接口的swagger")
    @PostMapping("/swaggerPost")
    public void post(@RequestBody TestParam testParam){
        System.out.println(testParam);
    }

    @ApiOperation(value = "测试get接口的swagger")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "name", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "loginUserId", value = "用户ID", dataType = "String", paramType = "query", required = true)
    })
    @GetMapping("/swaggerGet")
    public void get(@RequestParam String name, @RequestParam String loginUserId) {
    }
}
